<style type="text/css">
.act
{
    opacity: 0.8;
}

.act:hover
{
    opacity: 1;
}
#chitietleft
{
    float: left;
    margin: 20px 80px 20px ;
    box-shadow: 5px 5px 5px #666;
    position: relative;
    left: 10px;
}
#chitietright
{
    font-size: 14px;
    margin-left: 0px;
    height: 300px;
}
.label
{
    text-decoration:underline;
    font-size: 12px;
    color: #555;
}
#motasp
{
    clear: both; 
    margin: 50px;
    
}
</style>

<?php
	if(isset($_REQUEST["id"]) == false)
		header("location:trangchu.php");
	
	include_once("template/DataProvider.php");
	$id = $_REQUEST["id"];
	$query = "SELECT 
    s.MaSP,
    s.TenSP,
    s.GiaSP,
    s.HinhURL,
    s.SoLuongTon,
    s.SoLuotXem,
    s.MoTaSP,
    s.MaLSP,
    s.MaHSX,
    l.TenLSP,
    h.TenHSX
FROM
    sanpham s,
    loaisp l,
    hangsx h
WHERE
	s.MaLSP = l.MaLSP
    AND s.MaHSX = h.MaHSX AND s.MaSP = ".$id;
	$result = DataProvider::ExecuteQuery($query);
	$row = mysql_fetch_array($result);
	$SoLuotXem = $row["SoLuotXem"] +  1;
    $mahsx = $row["MaHSX"];
    $malsp = $row["MaLSP"];
    
    // lay thong tin user đăng sp này
    $query_ = "
    SELECT * FROM sanpham s, nguoidung nd WHERE s.MaSP = '".$id."' AND s.MaND = nd.MaND";
	$result_ = DataProvider::ExecuteQuery($query_);
	$row_ = mysql_fetch_array($result_); 
?>

<div id="chitietsp">
	<div id="chitietleft" style="border: 1px solid #99c7eb; width: 256px; height: 256px; margin-left: 0px;">
    	<img src="img_us/<?php echo $row["HinhURL"]; ?>" width="256" height="256" />
    </div>
    
    
    <table border ="0" cellspacing ="0" id="chitietright">
    	<tr >
            <td colspan="2">
            <span class="productname" style="font-size: 20px; color: #0048ff; text-shadow: 1px 1px #a8a8a8;"><?php echo $row["TenSP"]; ?></span>
            </td>
        </tr>

        <tr>
            <td style="width: 120px;">
        	<span class="label" >Giá:</span>
            </td>
            <td>
            <span class="price" style="color: red;"><b><?php echo number_format($row["GiaSP"]);?> VNĐ</b></span>
            </td>
        </tr>
        
        <tr>
            <td>
        	<span class="label" >Hãng sản xuất:</span>
            </td>
            <td>
            <span class="factory"><?php echo $row["TenHSX"]; ?></span>
            </td>
        </tr>
        
        <tr>
            <td>
        	<span class="label" >Loại sản phẩm:</span>
            </td>
            <td>
            <span class="data"><?php echo $row["TenLSP"];?></span>
            </td>
        </tr>

        <tr>
            <td>
        	<span class="label">Số lượng:</span>
            </td>
            <td>
            <span class="data"><?php echo $row["SoLuongTon"];?> sản phẩm</span>
            </td>
        </tr>
        
        <tr>
            <td>
        	<span class="label">Số lược xem:</span>
            </td>
            <td>
            <span class="data"><?php echo $SoLuotXem;?> lược</span>
            </td>
        </tr>
        
            
            

        <br />
        <?php
			if(isset($_SESSION["MaTaiKhoan"]) == true)
			{
				?>
                	<tr>
                        <td colspan="2" style="height: 70px;"> 
                        <a href="pages/xlThemVaoGioHang.php?id=<?php echo $row["MaSP"];?>">
                            <img src="images/addtocart.png" width="150" height="45" />
                        </a>
                        </td>
                    </tr>
                <?php
			}
		?>
    </table>
    
    
    
    
                <div id="thongtinhseller" style="text-align: left;">

        <?php
            if(isset($_REQUEST['id']))
            {
                $MaSP = $_REQUEST['id'];
                $querysp = "SELECT * FROM sanpham sp, nguoidung nd WHERE sp.MaSP = '".$MaSP."' AND sp.MaND = nd.MaND  ";
                $resultsp = DataProvider::executeQuery($querysp);
                $rowsp = mysql_fetch_array($resultsp);
                
        ?>
                <fieldset>
                    <legend style="text-align: left; color: #0080C0; font-size: 16px;">Thông tin người bán</legend>
                    <div>
                        <div><strong>Người bán</strong> :<?php echo $rowsp['TenHienThi'] ?> </div>
                        <div><strong>Địa chỉ</strong> : <?php echo $rowsp['DiaChi']  ?>  </div>
                        <div><strong>Số điện thoại</strong> : <?php echo $rowsp['SDT']  ?>  </div>
                        <div style="color: blue;"><strong style="color: black;">Email</strong> :<?php echo $rowsp['Email']  ?>  </div>
                    </div>   
                </fieldset>
        <?php
        
            }
        ?>
</div>
    <fieldset id="motasp">
        	<legend class="label" style="font-size: 20px; color: #003366; font-weight: bold;"><u>Mô tả sản phẩm:</u></legend>
            <br />
            <span class="data"><?php echo $row["MoTaSP"]?></span>
    </fieldset>
    <br /><br /><br /><br />
    <!-------------------------------------Map-------------------------------------->
    
    <?php
    if($row_['kinhdo'] != "" && $row_['vido'] != "")
    {
        $kd = $row_['kinhdo'];
        $vd = $row_['vido'];
    ?>
    
    <body onLoad="bando(<?php echo $kd; ?>,<?php echo $vd; ?>)">
    <div id="map" style="height:300px; width:700px"></div>
    </body>
    
    <?php
    }
    ?>
    
    <br /><br /><br /><br />
    
    <!---------------------------------comment-------------------------------------->
    <div>
        <?php
    				$query1 = " SELECT * FROM comment cm, nguoidung nd WHERE MaSP = '".$id."' AND cm.MaND = nd.MaND ORDER BY ThoiGian DESC ";
                    $result1 = DataProvider::executeQuery($query1);
        ?>
              
       
       <?php

       ?>             
                <!-- <div style="font-size: 20px; color: blue;">Nhận xét về sản phẩm </div> -->
           <?php     
                while ($row1=mysql_fetch_array($result1))
        			{
        			     
    	   ?>                            
                                <div style="background-image: url(./images/bg-comment.jpg); height: 34px; width: 510px; margin-left: 60px; margin-bottom: -22px;"></div>
                                 <fieldset style="border-radius: 15px; background: #b0b0b0; width: 500px; margin-left: 50px;">
                                     <legend style="margin-left: 0px; "></legend>
                                     <table cellpadding="0" border="0" style="text-align: left; margin-left: 0px;">
                                         <tr>   
                                             <td ><img src="<?php echo $row1['MaHinh']; ?>" width="50" height="50" /> </td>
                                             <td><img src="./images/icon-next-comment.png" width="13" height="13" /> </td>
                                             <td>
                                                 <p style="border: 0px solid #0080C0; background: #ffffff; width: 430px; margin-left: 0px; text-align: left; border-radius: 2px; font-size: 15px; font-style: italic; color: #007eb8;" >
                                                     <?php echo $row1['NoiDung'] ; ?>
                                                     <p style="font-size: 12px; color: #0040ff;">
                                                      <?php echo $row1['TenDangNhap']; ?>
                                                     </p>
                                                     <p style="font-size: 12px; color: #3b3b3b;">
                                                     Email : <?php echo $row1['Email']; ?>
                                                     </p>
                                                     <p style="font-size: 12px; color: #3b3b3b;">
                                                     Đăng vào lúc: <?php echo $row1['ThoiGian']; ?>
                                                     </p>
                                                 </p>
                                             </td>
                                             <?php
                                                if(isset($_SESSION['MaLoaiTaiKhoan']) == 2)
                                                {
                                             ?>
                                             <td>
                                                <p style="width: 50px; text-align: right;">
                                                <a href="trangchu.php?act=16&id=<?php echo $row1['MaComment']; ?>">
                                                    <img class="act" src="./images/delete-icon.png" height="25" width="25"/>
                                                </a>
                                                </p>
                                             </td>
                                             <?php
                                                }
                                                else
                                                    echo "";                                                
                                             ?>
                                            </tr>
                                     </table>
                                 </fieldset><br /><br />
        
            <?php 
                    }
                
        ?>
            	
    </div>            
    <div style="margin-left: 50px;">
        <br /><br /><br />
        <div style="font-size: 20px; color: #575757; ">comment</div>
        <form action="trangchu.php?act=13&id=<?php echo $id; ?>" method="post" onSubmit="return KiemTraDangComment()">
            <textarea id="comment" name="comment" style="width: 525px; height: 160px; background: #EEEEEE; border: 1px dashed #0091ff; color: #0272bd;"></textarea>
            
            
            <div style="margin-left: 250px;">
                <input type="submit" value="  " style=" width: 56px; height: 32px; background-image: url('images/button_guicomment.jpg'); ; border-radius: 5px; color: white;" />
            </div>
        </form>
    </div>
    
</div>
<br /><br />
<hr style="width: 500px;" />
<br /><br />

 <!------------------------- những sản phẩm cùng loại --------------------->
<div id="spcungloai" style="text-align: center; color: #0099FF;">
    <h4 style="color: ;"><u>Các sản phẩm đề xuất: </u></h4>
    <br />
    <?php
    $query1 = "
    SELECT * 
    FROM sanpham s, nguoidung nd 
    WHERE s.BiXoa='0' AND nd.MaND = s.MaND AND s.MaHSX = '".$mahsx."' AND s.MaLSP= '".$malsp."' LIMIT 1,5  "; 
											
	$result1 = DataProvider::ExecuteQuery($query1);

	while($row = mysql_fetch_array($result1))
	{
		include("templateSanPham.php"); 
   
	}
    ?>
    
</div>
<?php
	//Cap nhat lai so luoc xem tang len 1
	
	$query = "UPDATE sanpham SET SoLuotXem = ".$SoLuotXem." WHERE MaSP = ".$id;
	DataProvider::ExecuteQuery($query);//
?>

